<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title></title>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
				$("#btnAdd").button({
		            icons: {
		                primary: "ui-icon-plusthick"
		            }
				}).click(function(){
					$("#job").val("add");
					$("#searchForm").submit();
				});
				$("#btnUpload").button({
		            icons: {
		                primary: "ui-icon-arrowthickstop-1-n"
		            }
				}).click(function(){
					$("#job").val("initUpload");
					$("#searchForm").submit();
				});
				$("#btnSearch").button({
		            icons: {
		                primary: "ui-icon-search"
		            }
				}).click(function(){
					$("#job").val("search");
					$("#searchForm").submit();
				});
				$("[name=btnEdit]").button({
		            icons: {
		                primary: "ui-icon-pencil"
		            },
		            text:false
				});
				$("[name=btnView]").button({
		            icons: {
		                primary: "ui-icon-search"
		            },
		            text:false
				});
				
				$("[name=btnDel]").button({
		            icons: {
		                primary: "ui-icon-closethick"
		            },
		            text:false
				});
				$("#btnExport").button({
		            icons: {
		                primary: "ui-icon-arrowthickstop-1-s"
		            }
				}).click(function(){
					var venderTypeM = "";
					var venderTypeP = "";
					if ($("#vendetTypeM").is(":checked")) {
						venderTypeM = $("#vendetTypeM").val();
					}
					if ($("#vendetTypeP").is(":checked")) {
						venderTypeP = $("#vendetTypeP").val();
					}
					window.location='${pageContext.request.contextPath}/acc6?app=ACC60107&job=exportData&provinceId=' + $("#provinceId").val() + "&venderCode=" + $("#venderCode").val() + "&vanderName=" + $("#vanderName").val() + "&venderAccount=" + $("#venderAccount").val() + "&venderType=" + venderTypeM + ":" + venderTypeP;
				});
			});
			function editVender(provinceId, venderCode, venderType){
				window.location='${pageContext.request.contextPath}/acc6?app=ACC60107&job=viewEdit&provinceId='+provinceId+'&venderCode='+venderCode+'&venderType='+venderType;
			}
			function deleteVender(provinceId, venderCode){
				if(confirm('ยืนยันการลบข้อมูลหน่วยบริการ/คู่สัญญา')==true){
					window.location='${pageContext.request.contextPath}/acc6?app=ACC60107&job=delete&provinceId='+provinceId+'&venderCode='+venderCode;
				}
			}
		</script>
	</head>
	<body>
		<c:set var="auth" value="${el:getMapValue(menuAuth, 'ACC60107')}"/>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="searchForm" id="searchForm" action="${pageContext.request.contextPath}/acc6" method="post">
		<input type="hidden" name="app" id="app" value="ACC60107"/>
		<input type="hidden" name="job" id="job" value="${job}"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC60107}</b></th>
			</tr>
			<tr>
				<td align="right" colspan="2">
					<!-- <button type="button" name="btnAdd1" id="btnAdd1" class="acc67-button"> สสอ. </button> -->
					<c:if test="${fn:contains(auth, 'I')}">
						<button type="button" name="btnAdd" id="btnAdd" class="acc67-button"> เพิ่มคู่สัญญาระดับจังหวัด </button>
						<button type="button" class="acc67-button" name="btnExport" id="btnExport">Export Data</button>
						<c:if test="${userInfo.roleId == '1'}">
							<button type="button" name="btnUpload" id="btnUpload" class="acc67-button"> upload file  </button>
						</c:if>
					</c:if>
				</td>
			</tr>
			<tr>
				<td width="20%" class="bold">จังหวัด : </td>
				<td>
					<c:if test="${userInfo.areaLevel =='3'}">
						<c:forEach var="data" items="${userInfo.listUserProvice}">
							${data.provinceName}
							<input type="hidden" name="provinceId" id="provinceId" value="${data.provinceId}">
						</c:forEach>
					</c:if>
					<c:if test="${userInfo.areaLevel=='1' || userInfo.areaLevel=='2'}">
						<select name="provinceId" id="provinceId">
							<option value="">----- เลือก -----</option>
							<c:forEach var="data" items="${userInfo.listUserProvice}">
								<c:if test="${data.provinceId == provinceId}" var="provinceSeleted"/>
								<option value="${data.provinceId}" ${provinceSeleted?'selected':''}>${data.provinceName}</option>
							</c:forEach>
						</select>
					</c:if>
				</td>
			</tr>
			<tr>
				<td class="bold">รหัสหน่วยบริการ/คู่สัญญา : </td>
				<td>
					<input type="text" name="venderCode" id="venderCode" size="12" value="${venderCode}">
				</td>
			</tr>
			<tr>
				<td class="bold">ชื่อหน่วยบริการ/คู่สัญญา : </td>
				<td>
					<input type="text" name="vanderName" id="vanderName" value="${vanderName}">
				</td>
			</tr>
			<tr>
				<td class="bold">เลขที่บัญชี : </td>
				<td>
					<input type="text" name="venderAccount" id="venderAccount" value="${venderAccount}">
				</td>
			</tr>
			<tr>
				<td  class="bold">ประเภท : </td>
				<td>
					<input type="checkbox" name="vendetType" ${!empty vendetTypeM?'checked':''} id="vendetTypeM" value="M|S"/>หน่วยบริการ/คู่สัญญา จากระบบกลาง
					<!-- <input type="checkbox" name="vendetType" ${!empty vendetTypeA?'checked':''} id="vendetTypeA" value="A"/>สสอ. -->
					<input type="checkbox" name="vendetType" ${!empty vendetTypeP?'checked':''} id="vendetTypeP" value="C|T"/>คู่สัญญาระดับจังหวัด
				</td>
			</tr>
			<%-- <tr>
				<td  class="bold">ประเภทการจ่าย : </td>
				<td>
					<input type="checkbox" name="venderExpense" ${!empty venderExpenseT?'checked':''} id="venderExpenseT" value="T"/>จ่ายโอน
					<input type="checkbox" name="venderExpense" ${!empty venderExpenseC?'checked':''} id="venderExpenseC" value="C"/>จ่ายเช็ค
				</td>
			</tr> --%>
			<tr>
				<td colspan="2" align="center">
					<button type="submit" name="btnSearch" id="btnSearch" class="acc67-button"> ค้นหาข้อมูล </button>
				</td>
			</tr>
		</table>
		<br>
		<c:if test="${!empty pageBean.pageData}">
			<fieldset>
				<legend> ข้อมูลหน่วยบริการ/คู่สัญญา  </legend>
					<table width="100%" class="acc67-grid ui-widget ui-widget-content" border="0">
						<tr>
							<th  align="center" class="ui-state-default" onclick="pageControl('S', 'VENDER_CODE');"><span id="VENDER_CODE" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>รหัสหน่วยบริการ/คู่สัญญา</th>
							<th  align="center" class="ui-state-default" onclick="pageControl('S', 'VENDER_NAME');"><span id="VENDER_NAME" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>ชื่อหน่วยบริการ/คู่สัญญา</th>
							<th  align="center" class="ui-state-default" onclick="pageControl('S', 'VENDER_ACCOUNT_NAME_TH');"><span id="VENDER_ACCOUNT_NAME_TH" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>ชื่อบัญชีเงินฝากธนาคาร</th>
							<th  align="center" class="ui-state-default" onclick="pageControl('S', 'VENDER_ACCOUNT');"><span id="VENDER_ACCOUNT" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>เลขที่บัญชีเงินฝากธนาคาร</th>
							<th  align="center" class="ui-state-default" onclick="pageControl('S', 'ACTIVE');" width="5%"><span id="ACTIVE" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>สถานะ</th>
							<th  align="center" class="ui-state-default" width="5%">แก้ไข</th>
							<!-- <th  align="center" class="ui-state-default" width="5%">เรียกดู</th>-->
							<c:if test="${fn:contains(auth, 'D')}">
								<th  align="center" class="ui-state-default" width="5%">ลบ</th>
							</c:if>
						</tr>
						<c:forEach var="data" items="${pageBean.pageData}" varStatus="x">
							<tr class="grid-tr-${x.count % 2}">
								<td align="center">${data.venderCode}</td>
								<td>${data.venderName}</td>
								<td>${data.venderAccountNameTh}</td>
								<td align="center">${data.venderAccount}</td>
								<td align="center">${el:statusActive(data.active)}</td>
								<!-- <c:if test="${data.venderType != 'M' && data.venderType != 'A'}">
									<td align="center">
										<c:if test="${fn:contains(auth, 'U') && userInfo.areaLevel !='2'}">
											<button type="button" id="btnEdit" name="btnEdit" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>
										</c:if>
									</td>
									<td align="center">
										<c:if test="${userInfo.areaLevel=='2'&& fn:contains(auth, 'S')}">
											<button type="button" id="btnView" name="btnView" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>	
										</c:if>
									</td>
								</c:if>
								<c:if test="${data.venderType == 'M' || data.venderType == 'A'}">
									<c:if test="${empty data.venderAccount}">
										<td align="center">		
											<c:if test="${fn:contains(auth, 'U')}">
												<button type="button" id="btnEdit" name="btnEdit" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>
											</c:if>
										</td>
										<td align="center"></td>
									</c:if>
									<c:if test="${!empty data.venderAccount}">
										<td align="center"></td>
										<td align="center">	
											<c:if test="${fn:contains(auth, 'S')}">
												<button type="button" id="btnView" name="btnView" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>
											</c:if>
										</td>
									</c:if>
								</c:if>-->
								<td align="center">&nbsp;
									<c:if test="${fn:contains(auth, 'U')}">
										<c:if test="${userInfo.roleId == '1'}">
											<button type="button" id="btnEdit" name="btnEdit" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>
										</c:if>
										<c:if test="${userInfo.roleId != '1' && data.venderType != 'M'}">
											<button type="button" id="btnEdit" name="btnEdit" class="acc67-button" onclick="editVender('${data.provinceId}','${data.venderCode}','${data.venderType}')"></button>
										</c:if>
									</c:if>
								</td>
								<c:if test="${fn:contains(auth, 'D')}">
									<c:set var="isUsed" value="${el:isVenderUsed(data.venderCode)}"/>
									<c:if test="${!isUsed && userInfo.roleId == '1'}">
										<td align="center">
											<button type="button" id="btnDel" name="btnDel" class="acc67-button" onclick="deleteVender('${data.provinceId}','${data.venderCode}')"></button>
										</td>
									</c:if>
									<c:if test="${isUsed}">
										<td>&nbsp;&nbsp;</td>
									</c:if>
								</c:if>		
							</tr>
						</c:forEach>
					</table>
				<input type="hidden" name="formPage" id="formPage" value="searchForm"/>
				<c:import url="/apps/page.jsp"/>
			</fieldset>
		</c:if>
		</form>
	</body>
</html>